<?php

/**
 * Created by PhpStorm.
 * User: firebroo
 * Date: 8/11/16
 * Time: 9:18 AM
 */
class Utils
{
    public static function timediff( $begin_time, $end_time )
    {
        if ( $begin_time < $end_time ) {
            $starttime = $begin_time;
            $endtime = $end_time;
        } else {
            $starttime = $end_time;
            $endtime = $begin_time;
        }
        $timediff = $endtime - $starttime;
        $days = intval( $timediff / 86400 );
        $remain = $timediff % 86400;
        $hours = intval( $remain / 3600 );
        $remain = $remain % 3600;
        $mins = intval( $remain / 60 );
        $secs = $remain % 60;
        $ret = "";
        if ($days) {
            $ret .= $days."天";
        }
        if ($hours) {
            $ret .= $hours."小时";
        }
        if ($mins) {
            $ret .= $mins."分";
        }
        if ($secs) {
            $ret .= $secs."秒";
        }
        return $ret;
    }
}